﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SummerTraining
{
    public class Extractor
    {
        public Fruit fruit;

        public event Exam PreExam;
        public event Exam PostExam;

        public void Extract()
        {
            Console.WriteLine("开始执行事前检查！");
            if (PreExam == null)
            {

            }
            if (PreExam == null || PreExam(fruit))
            {
                Console.WriteLine("榨汁中...");

                if (PostExam == null || PostExam(fruit))
                {
                    Console.WriteLine("榨汁成功，请饮用");
                }
                else
                {
                    Console.WriteLine("事后检查失败，倒掉");
                }
            }
            else
            {
                Console.WriteLine("事前检查没有通过");
            }
        }
    }

    public delegate bool Exam(Fruit fruit);

    public class Fruit
    {
        public int Weight { get; set; }

        private int mature;
        public int Mature
        {
            set
            {
                if (value < 0)
                    mature = 0;
                if (value > 10)
                {
                    mature = 10;
                }
                else
                {
                    mature = value;
                }
            }
            get
            {
                return mature;
            }
        }

        public int GetJuice()
        {
            return Weight * mature / 10;
        }
    }

    public class Apple : Fruit
    {
    }

    public class Orange : Fruit
    {
    }
}
